﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class GameSweet : MonoBehaviour {
    private int x;
    private int y;
    public int X
    {
        get { return x; }
        set {
            if (canMove())
            {
                x = value;
            }
                 
        }
    }
    public int Y
    {
        get { return y; }
        set {
            if (canMove())
            {
                y = value;
            }
            
        }
    }
    private GameManager.SweetsType type;
    public GameManager.SweetsType Type
    {
        get { return type; }
    }
    [HideInInspector]
    public GameManager gameManger;
    private MovedSweet moveCompoment;

    public MovedSweet MoveCompoment
    {
        get { return moveCompoment; }
    }

    private ColorSweet coloredCompoment;

    public ColorSweet ColoredCompoment
    {
        get { return coloredCompoment; }
    }

    private ClearedSweet clearedComponent;

    public ClearedSweet ClearedComponent
    {
        get { return clearedComponent; }
    }
   
    public bool canMove()
    {
        return moveCompoment != null;
    
    }

    public bool canColor()
    {
        return coloredCompoment != null;

    }

    public bool CanClear()
    {
        return clearedComponent != null;
    }

    private void Awake()
    {
        moveCompoment = GetComponent<MovedSweet>();
        coloredCompoment = GetComponent<ColorSweet>();
        clearedComponent = GetComponent<ClearedSweet>();
    }
    

    public void init(int _x,int _y,GameManager _gamanager,GameManager.SweetsType _type)
    {
        x = _x;
        y = _y;
        gameManger = _gamanager;
        type = _type;
    
    }
    private void OnMouseEnter()
    {
        gameManger.EnterSweet(this);
    }
    private void OnMouseDown()
    {
        gameManger.PressSweet(this);
    }
    private void OnMouseUp()
    {
        gameManger.ReleaseSweet();
    
    }
}
